package com.tianqu.tms.www.check.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferAcceptedInfo;

import net.sf.json.JSONArray;

public class CheckCarPrintInfoAjaxAction extends TmsAjaxAction {
	@Override
	public void process(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws TmsException {
		String serial = request.getParameter("serial");
 
		TxController controller = TxController.getTxController();
		try {
			TransferAcceptedInfo accept = new TransferAcceptedInfo();
			if(StringUtil.isNotBlank(serial)){
				accept = accept.getAcceptInfoBySerial(serial, "");
				if(accept!=null){
					Map map = new HashMap<String, String>();
					map.put("serial", serial);
					map.put("checkPriceDate", accept.getCheckPriceDate());
					map.put("vin", accept.getVin());
					map.put("licensePlate", accept.getLicensePlate());
					map.put("transferPriceDate", accept.getTransferPriceDate());
					map.put("carOwner", accept.getCarOwner());
					map.put("cyCardType", accept.getCy_cardType());
					map.put("memberName", accept.getMemberRealName());
					map.put("transferPriceDate", accept.getTransferPriceDate());
					map.put("checkPrice",Registry.getConfigFromDb(TmsConstants.CHECKPRICE));
					responseValues(response, JSONArray.fromObject(map).toString(),TEXT);
				}
			}
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
		}
        String log = "CheckCarPrintInfo,serial:"+serial +" response:"+response;
		logger.debug(log);
		responseValues(response, "", TEXT);
	}
	public static void main(String[] args) {
		TransferAcceptedInfo accept = new TransferAcceptedInfo();
		accept.setAgentName("fda");
		System.out.println(JSONArray.fromObject(accept));
	}
}
